<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>多态</title>
</head>
<body>

<script>
    class Vehicle{}
        class Motorcycle extends Vehicle{
            testMotor(){
                console.log("摩托车的方法");
            }
        }
        class Car extends Vehicle{
            testCar(){
                console.log("小轿车的方法");
            }
        }
        const v = new Vehicle();
        const c = new Car();
        const m = new Motorcycle();
        function run(obj) {
            //对象             类型
            //instanceof运算符，会指出某个对象是否属于某个给定类。
            if(obj instanceof Motorcycle){
                obj.testMotor();
            }else if(obj instanceof Car){
                obj.testCar();
            }
        }
        run(m);
</script>
</body>
</html>